﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using TierService;
public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.TXT_USERCODE.Focus();
        }
    }
    protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {

        if ((Session["CheckCode"] != null) || (Session["CheckCode"].ToString() != ""))
        {
            if (Session["CheckCode"].ToString().ToLower() != this.CheckCode.Value.ToLower())
            {
                this.lblMsg.Text = "所填写的验证码与所给的不符 !";
                Session["CheckCode"] = null;
                return;
            }
            else
            {
                Session["CheckCode"] = null;
            }
        }
        else
        {
            Response.Redirect("login.aspx");
        }

        if (Authentication.ValidUser(this.TXT_USERCODE.Text.Trim(), this.TXT_PASSWORD.Text.Trim()))
        {
            if (Session["UserInfo"] == null)
                Session["UserInfo"] = SessionHelper.Get("UserInfo");
            Context.Response.Redirect("Default.html"); // 重定向到用户申请的初始页面
        }
        else
        {
            // 用户身份未被确认时的代码
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('登录失败，用户名或密码错误！！');</script>");
        }
    }
}
